import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('通知组件'),
        ),
        body: SystemNotifyWidget(),
      ),
    );
  }
}

// 系统自带通知,组件内部的一些变化会发出通知，如ListView的滚动会发出通知
class SystemNotifyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return NotificationListener(
        onNotification: (notification) {
          switch (notification.runtimeType) {
            case ScrollStartNotification:
              debugPrint('滚动开始');
              break;
            case ScrollUpdateNotification:
              debugPrint('滚动中');
              break;
            case ScrollEndNotification:
              debugPrint('滚动停止');
              break;
            case OverscrollNotification:
              debugPrint('滚动到边界');
              break;
          }
          return true;
        },
        child: ListView.builder(
          itemBuilder: (context, index) => Text('数据$index'),
          itemExtent: 30.0,
          itemCount: 30,
        ));
  }
}
